﻿package net.wangit.view.unit.navigator;

import net.wangit.support.PageNavigator;

public class SelectPageNavigator implements PageNavigator {

	public SelectPageNavigator() {
	}

	public String getHtml(String domain, String unitId, int dataSize,
			int maxSize, int listSize, int pageNumber, int maxPageNumber) {
		StringBuffer html = new StringBuffer();
		html.append("<select class=\"").append("NS").append("\" name=\"")
				.append(unitId).append(".p").append(
						"\" onchange=\"doSubmit()\">");
		for (int i = 0; i < maxPageNumber; i++)
			if (i + 1 >= maxPageNumber)
				setOption(html, pageNumber, maxPageNumber, i * listSize + 1,
						maxSize);
			else
				setOption(html, pageNumber, i + 1, i * listSize + 1, (i + 1)
						* listSize);

		html.append("</select>");
		return html.toString();
	}

	private void setOption(StringBuffer html, int pageNumber, int itemNumber,
			int start, int end) {
		html.append("<option value=\"").append(itemNumber).append("\"");
		if (pageNumber == itemNumber)
			html.append(" selected");
		html.append(">").append(start).append("-").append(end).append(
				"</option>");
	}
}
